package com.ruoyi.web.controller.golang;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CommunityUser;
import com.ruoyi.system.service.ICommunityUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社群用户关系Controller
 * 
 * @author ruoyi
 * @date 2025-01-12
 */
@Controller
@RequestMapping("/system/user")
public class CommunityUserController extends BaseController
{
    private String prefix = "system/user";

    @Autowired
    private ICommunityUserService communityUserService;

    @RequiresPermissions("system:user:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    /**
     * 查询社群用户关系列表
     */
    @RequiresPermissions("system:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CommunityUser communityUser)
    {
        startPage();
        List<CommunityUser> list = communityUserService.selectCommunityUserList(communityUser);
        return getDataTable(list);
    }

    /**
     * 导出社群用户关系列表
     */
    @RequiresPermissions("system:user:export")
    @Log(title = "社群用户关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CommunityUser communityUser)
    {
        List<CommunityUser> list = communityUserService.selectCommunityUserList(communityUser);
        ExcelUtil<CommunityUser> util = new ExcelUtil<CommunityUser>(CommunityUser.class);
        return util.exportExcel(list, "社群用户关系数据");
    }

    /**
     * 新增社群用户关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存社群用户关系
     */
    @RequiresPermissions("system:user:add")
    @Log(title = "社群用户关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CommunityUser communityUser)
    {
        return toAjax(communityUserService.insertCommunityUser(communityUser));
    }

    /**
     * 修改社群用户关系
     */
    @RequiresPermissions("system:user:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        CommunityUser communityUser = communityUserService.selectCommunityUserById(id);
        mmap.put("communityUser", communityUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存社群用户关系
     */
    @RequiresPermissions("system:user:edit")
    @Log(title = "社群用户关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CommunityUser communityUser)
    {
        return toAjax(communityUserService.updateCommunityUser(communityUser));
    }

    /**
     * 删除社群用户关系
     */
    @RequiresPermissions("system:user:remove")
    @Log(title = "社群用户关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(communityUserService.deleteCommunityUserByIds(ids));
    }
}
